﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;

namespace Gemciler_Uretim
{
    public partial class KullaniciTanimi : DevExpress.XtraEditors.XtraForm
    {
        public KullaniciTanimi()
        {
            InitializeComponent();
        }
        public string user_skin_ismi;
        SqlConnecitonClass sqlbaglanti = new SqlConnecitonClass();
        string kayıt_tipi;
        private void simpleButton13_Click(object sender, EventArgs e)
        {
            KayitSecim fr = new KayitSecim();
            fr.sorgu = "SELECT ku_kodu AS KODU ,ku_adi AS ADI FROM TK_KULLANICI_TANIMLARI ";
            fr.ShowDialog();
            text_kodu.Text = fr.secilen_kod;
            text_adi.Text = fr.secilen_adi;
            text_email.Text = Convert.ToString(sqlbaglanti.CommScalar("SELECT ku_email FROM TK_KULLANICI_TANIMLARI where ku_kodu=" + fr.secilen_kod + "", CommandType.Text));
            text_mail_pop.Text = Convert.ToString(sqlbaglanti.CommScalar("SELECT ku_mail_pop FROM TK_KULLANICI_TANIMLARI where ku_kodu=" + fr.secilen_kod + "", CommandType.Text));
            text_mail_sifre.Text = Convert.ToString(sqlbaglanti.CommScalar("SELECT ku_mail_sifre FROM TK_KULLANICI_TANIMLARI where ku_kodu=" + fr.secilen_kod + "", CommandType.Text));
            text_mail_unvan.Text = Convert.ToString(sqlbaglanti.CommScalar("SELECT ku_mail_unvani  FROM TK_KULLANICI_TANIMLARI where ku_kodu=" + fr.secilen_kod + "", CommandType.Text));
            text_sifre.Text = Convert.ToString(sqlbaglanti.CommScalar("SELECT ku_pw FROM TK_KULLANICI_TANIMLARI where ku_kodu=" + fr.secilen_kod + "", CommandType.Text));
           


        }
        private void EkranHazirla()
        {


            gridControl1.DataSource = sqlbaglanti.ShowTable("SELECT [ku_kodu] AS KODU      ,[ku_adi] AS ADI      ,[ku_pw] AS PW "
      + ",[ku_mikro_kodu] AS MYEKODU        ,[ku_firma] AS FİRMA   "
      + ",[ku_sistemde] AS PROGRAM      ,[ku_email] AS EMAİL"
      + ",[ku_mail_sifre] AS [EMAİL ŞİFRE]      ,[ku_mail_unvani] AS [EMAİL ÜNVANI]"
      + ",[ku_mail_pop] AS [POP]  FROM [TK_KULLANICI_TANIMLARI]", CommandType.Text);


            //this.gridView1.Columns["TARİH"].DisplayFormat.FormatString = "DD-MM-YYYY SS:dd";

            this.gridControl1.TabIndex = 0;
            this.gridView1.OptionsBehavior.AllowIncrementalSearch = false;
            this.gridView1.OptionsView.ShowAutoFilterRow = false;
            this.gridView1.OptionsView.ShowGroupPanel = false;
            this.gridView1.OptionsBehavior.Editable = false;
            this.gridView1.OptionsBehavior.ReadOnly = false;
            this.gridView1.OptionsView.ColumnAutoWidth = false;
            this.gridView1.OptionsView.HeaderFilterButtonShowMode = FilterButtonShowMode.Button;

            // this.gridView3.Columns["SIPRECNO"].Visible = false;
            this.gridView1.BestFitColumns();

        }
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void simpleButton3_Click(object sender, EventArgs e)
        {
            KayitSecim fr = new KayitSecim();
            fr.sorgu = "SELECT      [User_no] ,[User_name] AS KODU  ,[User_LongName] AS ADI   FROM [MikroDB_V14].[dbo].[KULLANICILAR] ";
            fr.ShowDialog();
            text_mye_kodu.Text = fr.secilen_kod;

        }

       

        private void KullaniciTanimi_Load(object sender, EventArgs e)
        {
            DevExpress.LookAndFeel.UserLookAndFeel.Default.SkinName = user_skin_ismi;
            DevExpress.Skins.SkinManager.EnableFormSkins();
            kayıt_tipi = "degiştir";


            this.WindowState = FormWindowState.Maximized;
            EkranHazirla();
        }

        private void buton_sakla_Click(object sender, EventArgs e)
        {
            sqlbaglanti.CommScalar("delete  from [TK_KULLANICI_TANIMLARI] where  ku_kodu=" + text_kodu.Text + "", CommandType.Text);
            sqlbaglanti.CommScalar("INSERT INTO [TK_KULLANICI_TANIMLARI]"
              + " ([ku_kodu]   ,[ku_adi]   ,[ku_pw]  ,[ku_mikro_kodu]  ,[ku_email],ku_firma,ku_mail_sifre,ku_mail_unvani,ku_mail_pop)"
              + " VALUES (" + text_kodu.Text + ",'" + text_adi.Text + "','" + text_sifre.Text + "','" + text_mye_kodu.Text + "','" + text_email.Text + "','" + text_firma_kodu.Text + "','" + text_mail_sifre.Text + "','" + text_mail_unvan.Text + "','" + text_mail_pop.Text + "')", CommandType.Text);
            MessageBox.Show("KAYIT TAMAMLANDI");
            EkranHazirla();
            
        }

        private void gridView1_Click(object sender, EventArgs e)
        {
            int index1 = gridView1.FocusedRowHandle;
            text_kodu.Text = gridView1.GetRowCellValue(index1, "KODU").ToString();
            text_adi.Text = gridView1.GetRowCellValue(index1, "ADI").ToString();
            text_mye_kodu.Text= gridView1.GetRowCellValue(index1, "MYEKODU").ToString();
            text_mail_pop.Text = gridView1.GetRowCellValue(index1, "POP").ToString();
            text_sifre.Text = gridView1.GetRowCellValue(index1, "PW").ToString();
            text_mail_sifre.Text = gridView1.GetRowCellValue(index1, "EMAİL ŞİFRE").ToString();
            text_mail_unvan.Text = gridView1.GetRowCellValue(index1, "EMAİL ÜNVANI").ToString();
            text_email.Text = gridView1.GetRowCellValue(index1, "EMAİL").ToString();
            text_firma_kodu.Text = gridView1.GetRowCellValue(index1, "FİRMA").ToString();
            text_kodu.Enabled = false;
          //  text_mye_kodu= false;
            kayıt_tipi = "degiştir";
        }

        private void buton_vazgec_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void buton_sil_Click(object sender, EventArgs e)
        {
            if (text_kodu.Text == "")

            { MessageBox.Show("Bir Kayıt Seçin"); }
            else
            {
                if (MessageBox.Show("" + text_kodu.Text + " Kayıt Silinecek   ", "Onay Ekranı", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {

                    sqlbaglanti.CommScalar("delete  from [TK_KULLANICI_TANIMLARI] where  ku_kodu=" + text_kodu.Text + "", CommandType.Text);
      
                }
            }
        }
    }
}